/*
 * GridModel.cpp
 *
 *  Created on: Dec 18, 2013
 *      Author: artech
 */

#include "GridModel.h"
#include "Sdq.h"

GridModel::GridModel()
{
   clear();
}

GridModel::~GridModel()
{
   for (quint8 i = 0; i < GRID_SIZE; ++i)
   {
      qDeleteAll(_grid[i]);
   }
}

SquareModel* GridModel::getSquareModel(quint8 lineNb, quint8 columnNb)
{
   return _grid[lineNb][columnNb];
}

void GridModel::clear()
{
   for (QVector<QVector<SquareModel*> >::iterator iIt = _grid.begin();
         iIt != _grid.end(); ++iIt)
   {
      qDeleteAll(*iIt);
   }
   _grid.clear();
   _grid.resize(GRID_SIZE);
   for (quint8 i = 0; i < GRID_SIZE; ++i)
   {
      _grid[i].resize(GRID_SIZE);
      for (quint8 j = 0; j < GRID_SIZE; ++j)
      {
         _grid[i][j] = new SquareModel(i, j);
      }
   }
}
